package com.example.springbootdemo2023.core.config;

import com.example.springbootdemo2023.core.interceptors.LoginInterceptor;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

/**
 * 模块名称：拦截器配置类
 * 模块类型：
 * 编码人：高靖博
 * 创建时间：2023/3/1
 * 联系电话：18587388612
 */
// 1. 实现WebMvcConfigurer 接口
@Configuration
public class InterceptorConfig implements WebMvcConfigurer {

    //2.重写addInterceptors方法
    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        //3. 注册自定义编写的拦截器
        // 调用addInterceptor，参数传递拦截器实例
        InterceptorRegistration ic = registry.addInterceptor(new LoginInterceptor());
        //设置拦截器的拦截规则
        ic.addPathPatterns("/**");
        //放行拦截器（登录页面、登录请求、静态资源（js、css、img、video、font（字体文件））、阿里druid连接池监控中心、swaggerui）
        ic.excludePathPatterns(
                "/account/doLogin",
                "/reqCode/captcha",
                "/js/**",
                "/css/**",
                "/imgs/**",
                "/druid/**",
                "/swagger-ui.html/**",
                "/v2/**",
                "/webjars/**",
                "/swagger-resources/**",
                "/doc.html/**",
                "/captcha/get/**",
                "/captcha/check/**",
                "/account/checkIsUseXwyz/**",
                "/file/**",
                "/system/**"
                );
    }
}
